﻿/*
    Copyright 2012 Patricio Tapia Torres (patricio.tapia@gmail.com)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml;
using System.Windows.Forms;
using System.Collections;

namespace MarkupDesignForm
{
    public delegate void del_runaction(string xml);
    class getxml
    {
        struct str_enlace_eventos
        {
            public string objeto;
            public string accion;
        }

        struct str_acciones
        {
            public string nombre;
            public string codigoxml;
        }
        private gethtml get_web;
        private del_runaction v_del_runaction;
        private ArrayList lista_acc = new ArrayList();
        private ArrayList lista_obj_ev = new ArrayList();
        XmlDocument xdoc = new XmlDocument();
        XmlDocument xdoc2 = new XmlDocument();
        msg_error errorwin;
        Form2 fo;
        public void get_xml(string in_xml,Form1 p3)
        {
            string original_code = in_xml;
            v_del_runaction = new del_runaction(procesar_xml_ev);
            get_web = new gethtml();
            get_web.llamarpagina(v_del_runaction);
            fo = new Form2(p3);
            Button f_button;
            TextBox f_textbox;
            Label f_label;
            CheckBox f_checkbox;
            ComboBox f_combobox;
            DateTimePicker f_datetimepicker;
            ListBox f_listbox;
            ListView f_listview;
            ProgressBar f_progressbar;
            NumericUpDown f_numericupdown;
            RadioButton f_radiobutton;
            TreeView f_treeview;
            GroupBox f_groupbox;
            Panel f_panel;
            TabControl f_tabcontrol;
            ListViewItem f_listviewitem;
            ColumnHeader f_columnheader;

            //xdoc.LoadXml(xml_in);
            try
            {
                in_xml = in_xml.Replace("\r\n", "");
                in_xml = in_xml.Replace("\t", "");
                xdoc.LoadXml(in_xml);
                XmlNodeList lista = xdoc.GetElementsByTagName("mdf");
                /*
                foreach (XmlElement li in lista)
                {
                    foreach (XmlElement li2 in li.ChildNodes)
                    {
                        MessageBox.Show(li2.Name);
                    }
                }
                */
                XmlNodeList lista_f = ((XmlElement)lista[0]).GetElementsByTagName("form");
                foreach (XmlElement a in lista_f)
                {
                    #region Propiedades del Formulario
                    if (a.ParentNode.Name == "mdf")
                    {
                        if (a.GetAttribute("name").Length > 0)
                            fo.Name = a.GetAttribute("name");
                        if (a.GetAttribute("title").Length > 0)
                        {
                            fo.Text = a.GetAttribute("title");
                        }
                        if (a.GetAttribute("backcolor").Length > 0)
                        {
                            string[] rgb1 = a.GetAttribute("backcolor").Split(new char[] { ',' });
                            if (rgb1.Length == 3)
                            {
                                fo.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                            }
                        }
                        if (a.GetAttribute("controlbox").Length > 0)
                        {
                            if (a.GetAttribute("controlbox") == "false")
                                fo.ControlBox = false;
                            else if (a.GetAttribute("controlbox") == "true")
                                fo.ControlBox = true;
                            //else ERROR
                        }
                        if (a.GetAttribute("cursor").Length > 0)
                        {
                            switch (a.GetAttribute("cursor"))
                            {
                                case "AppStarting":
                                    fo.Cursor = Cursors.AppStarting;
                                    break;
                                case "Arrow":
                                    fo.Cursor = Cursors.Arrow;
                                    break;
                                case "Cross":
                                    fo.Cursor = Cursors.Cross;
                                    break;
                                case "No":
                                    fo.Cursor = Cursors.No;
                                    break;
                                case "WaitCursor":
                                    fo.Cursor = Cursors.WaitCursor;
                                    break;
                                case "Help":
                                    fo.Cursor = Cursors.Help;
                                    break;
                                case "Hand":
                                    fo.Cursor = Cursors.Hand;
                                    break;
                            }
                        }
                        if (a.GetAttribute("font").Length > 0)
                        {
                            string[] p = a.GetAttribute("font").Split(new char[] { ';' });
                            fo.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                        }
                        if (a.GetAttribute("forecolor").Length > 0)
                        {
                            string[] rgb1 = a.GetAttribute("backcolor").Split(new char[] { ',' });
                            if (rgb1.Length == 3)
                            {
                                fo.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                            }
                        }
                        if (a.GetAttribute("formborder").Length > 0)
                        {
                            switch (a.GetAttribute("formborder"))
                            {
                                case "fixed3d":
                                    fo.FormBorderStyle = FormBorderStyle.Fixed3D;
                                    break;
                                case "fixeddialog":
                                    fo.FormBorderStyle = FormBorderStyle.FixedDialog;
                                    break;
                                case "fixedsingle":
                                    fo.FormBorderStyle = FormBorderStyle.FixedSingle;
                                    break;
                                case "fixedtoolwindow":
                                    fo.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                                    break;
                                case "none":
                                    fo.FormBorderStyle = FormBorderStyle.None;
                                    break;
                                case "sizable":
                                    fo.FormBorderStyle = FormBorderStyle.Sizable;
                                    break;
                                case "sizabletoolwindow":
                                    fo.FormBorderStyle = FormBorderStyle.SizableToolWindow;
                                    break;
                                //else ERROR
                            }
                        }
                        if (a.GetAttribute("icon").Length > 0)
                        {
                            //fo.Icon = new System.Drawing.Icon(
                        }
                        if (a.GetAttribute("mdi").Length > 0)
                        {
                            if (a.GetAttribute("mdi") == "true")
                                fo.IsMdiContainer = true;
                            else if (a.GetAttribute("mdi") == "false")
                                fo.IsMdiContainer = false;
                            //else ERROR
                        }
                        if (a.GetAttribute("maximizebutton").Length > 0)
                        {
                            if (a.GetAttribute("maximizebutton") == "1")
                                fo.MaximizeBox = true;
                            else if (a.GetAttribute("maximizebutton") == "0")
                                fo.MaximizeBox = false;
                        }
                        if (a.GetAttribute("minimizebutton").Length > 0)
                        {
                            if (a.GetAttribute("minimizebutton") == "1")
                                fo.MinimizeBox = true;
                            else if (a.GetAttribute("minimizebutton") == "0")
                                fo.MinimizeBox = false;
                        }
                        if (a.GetAttribute("showicon").Length > 0)
                        {
                            if (a.GetAttribute("showicon") == "1")
                                fo.ShowIcon = true;
                            else if (a.GetAttribute("showicon") == "0")
                                fo.ShowIcon = false;
                        }
                        if (a.GetAttribute("showintaskbar").Length > 0)
                        {
                            if (a.GetAttribute("showintaskbar") == "1")
                                fo.ShowInTaskbar = true;
                            else if (a.GetAttribute("showintaskbar") == "0")
                                fo.ShowInTaskbar = false;
                        }
                        if (a.GetAttribute("startposition").Length > 0)
                        {
                            switch (a.GetAttribute("startposition"))
                            {
                                case "centerparent":
                                    fo.StartPosition = FormStartPosition.CenterParent;
                                    break;
                                case "centerscreen":
                                    fo.StartPosition = FormStartPosition.CenterScreen;
                                    break;
                                case "manual":
                                    fo.StartPosition = FormStartPosition.Manual;
                                    break;
                                case "defaultbound":
                                    fo.StartPosition = FormStartPosition.WindowsDefaultBounds;
                                    break;
                                case "defaultlocation":
                                    fo.StartPosition = FormStartPosition.WindowsDefaultLocation;
                                    break;
                            }
                        }
                        if (a.GetAttribute("alwaysfront").Length > 0)
                        {
                            if (a.GetAttribute("alwaysfront") == "1")
                                fo.TopMost = true;
                            else if (a.GetAttribute("alwaysfront") == "0")
                                fo.TopMost = false;
                        }
                        if (a.GetAttribute("windowstate").Length > 0)
                        {
                            switch (a.GetAttribute("windowstate"))
                            {
                                case "minimized":
                                    fo.WindowState = FormWindowState.Minimized;
                                    break;
                                case "maximized":
                                    fo.WindowState = FormWindowState.Maximized;
                                    break;
                                case "normal":
                                    fo.WindowState = FormWindowState.Normal;
                                    break;
                            }
                        }
                        if (a.GetAttribute("size").Length > 0)
                        {
                            string[] p = a.GetAttribute("size").Split(new char[] { ',' });
                            fo.Size = new System.Drawing.Size(Convert.ToInt32(p[0]), Convert.ToInt32(p[1]));
                        }
                    #endregion
                        #region Procesar controles
                        foreach (XmlElement pch in a.ChildNodes)
                        {
                            bool add_aotro = false;
                            switch (pch.Name)
                            {
                                case "button":
                                    f_button = new Button();
                                    f_button.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_button.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_button.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_button.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_button.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_button.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_button.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_button.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_button.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_button.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_button.Enabled = false;
                                                break;
                                            case "text":
                                                f_button.Text = pch.GetAttribute("text");
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_button);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_button);
                                    break;
                                case "textbox":
                                    f_textbox = new TextBox();
                                    f_textbox.Text = pch.InnerText;
                                    //bool add_aotro = false;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_textbox.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_textbox.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_textbox.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_textbox.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_textbox.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_textbox.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_textbox.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_textbox.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_textbox.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_textbox.Enabled = false;
                                                break;
                                            case "password":
                                                if (pch.GetAttribute("password") == "true")
                                                    f_textbox.PasswordChar = '*';
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_textbox);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_textbox);
                                    break;
                                case "label":
                                    f_label = new Label();
                                    f_label.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_label.Name = pch.GetAttribute("name");
                                                break;
                                            case "text":
                                                f_label.Text = pch.GetAttribute("text");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_label.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_label.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_label.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_label.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_label.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_label.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_label.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_label.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_label.Enabled = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_label);
                                                        }
                                                    }
                                                }
                                                break;

                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_label);
                                    break;
                                case "treeview":
                                    f_treeview = new TreeView();
                                    f_treeview.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_treeview.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_treeview.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_treeview.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_treeview.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_treeview.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_treeview.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_treeview.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_treeview.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_treeview.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_treeview.Enabled = false;
                                                break;
                                            case "pathnode":
                                                f_treeview.PathSeparator = pch.GetAttribute("pathnode");
                                                break;
                                            case "showrootline":
                                                if (pch.GetAttribute("showrootline") == "true")
                                                    f_treeview.ShowRootLines = true;
                                                else if (pch.GetAttribute("showrootline") == "false")
                                                    f_treeview.ShowRootLines = false;
                                                break;
                                            case "showlines":
                                                if (pch.GetAttribute("showlines") == "true")
                                                    f_treeview.ShowLines = true;
                                                else if (pch.GetAttribute("showlines") == "false")
                                                    f_treeview.ShowLines = false;
                                                break;
                                            case "showplus":
                                                if (pch.GetAttribute("showplus") == "true")
                                                    f_treeview.ShowPlusMinus = true;
                                                else if (pch.GetAttribute("showplus") == "false")
                                                    f_treeview.ShowPlusMinus = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_treeview);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_treeview);
                                    break;
                                case "checkbox":
                                    f_checkbox = new CheckBox();
                                    f_checkbox.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_checkbox.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_checkbox.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_checkbox.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_checkbox.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_checkbox.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_checkbox.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "appereance":
                                                if (pch.GetAttribute("appereance") == "normal")
                                                    f_checkbox.Appearance = Appearance.Normal;
                                                else if (pch.GetAttribute("appereance") == "button")
                                                    f_checkbox.Appearance = Appearance.Button;
                                                break;
                                            case "checked":
                                                if (pch.GetAttribute("checked") == "true")
                                                    f_checkbox.Checked = true;
                                                else if (pch.GetAttribute("checked") == "false")
                                                    f_checkbox.Checked = false;
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_checkbox.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_checkbox.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_checkbox.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_checkbox.Enabled = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_checkbox);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_checkbox);
                                    break;
                                case "radiobutton":
                                    f_radiobutton = new RadioButton();
                                    f_radiobutton.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_radiobutton.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_radiobutton.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_radiobutton.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_radiobutton.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_radiobutton.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_radiobutton.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "appereance":
                                                if (pch.GetAttribute("appereance") == "normal")
                                                    f_radiobutton.Appearance = Appearance.Normal;
                                                else if (pch.GetAttribute("appereance") == "button")
                                                    f_radiobutton.Appearance = Appearance.Button;
                                                break;
                                            case "checked":
                                                if (pch.GetAttribute("checked") == "true")
                                                    f_radiobutton.Checked = true;
                                                else if (pch.GetAttribute("checked") == "false")
                                                    f_radiobutton.Checked = false;
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_radiobutton.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_radiobutton.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_radiobutton.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_radiobutton.Enabled = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_radiobutton);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_radiobutton);
                                    break;
                                case "combobox":
                                    f_combobox = new ComboBox();
                                    f_combobox.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_combobox.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_combobox.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_combobox.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_combobox.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_combobox.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_combobox.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_combobox.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_combobox.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_combobox.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_combobox.Enabled = false;
                                                break;
                                            case "dropstyle":
                                                if (pch.GetAttribute("dropstyle") == "1")
                                                    f_combobox.DropDownStyle = ComboBoxStyle.DropDown;
                                                else if (pch.GetAttribute("dropstyle") == "2")
                                                    f_combobox.DropDownStyle = ComboBoxStyle.DropDownList;
                                                else if (pch.GetAttribute("dropstyle") == "3")
                                                    f_combobox.DropDownStyle = ComboBoxStyle.Simple;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_combobox);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_combobox);
                                    break;
                                case "datetimepicker":
                                    f_datetimepicker = new DateTimePicker();
                                    f_datetimepicker.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_datetimepicker.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_datetimepicker.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_datetimepicker.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_datetimepicker.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_datetimepicker.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_datetimepicker.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_datetimepicker.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_datetimepicker.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_datetimepicker.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_datetimepicker.Enabled = false;
                                                break;
                                            case "format":
                                                if (pch.GetAttribute("format") == "0")
                                                    f_datetimepicker.Format = DateTimePickerFormat.Long;
                                                else if (pch.GetAttribute("format") == "1")
                                                    f_datetimepicker.Format = DateTimePickerFormat.Short;
                                                else if (pch.GetAttribute("format") == "2")
                                                    f_datetimepicker.Format = DateTimePickerFormat.Time;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_datetimepicker);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_datetimepicker);
                                    break;
                                case "listbox":
                                    f_listbox = new ListBox();
                                    f_listbox.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_listbox.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_listbox.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_listbox.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_listbox.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_listbox.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_listbox.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_listbox.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_listbox.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "1")
                                                    f_listbox.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "0")
                                                    f_listbox.Enabled = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_listbox);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_listbox);
                                    break;
                                case "listview":
                                    f_listview = new ListView();
                                    f_listview.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_listview.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_listview.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_listview.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_listview.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_listview.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_listview.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_listview.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_listview.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_listview.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_listview.Enabled = false;
                                                break;
                                            case "checkboxes":
                                                if (pch.GetAttribute("checkboxes") == "true")
                                                    f_listview.CheckBoxes = true;
                                                else if (pch.GetAttribute("checkboxes") == "false")
                                                    f_listview.CheckBoxes = false;
                                                break;
                                            case "fullrowselect":
                                                if (pch.GetAttribute("fullrowselect") == "true")
                                                    f_listview.FullRowSelect = true;
                                                else if (pch.GetAttribute("fullrowselect") == "false")
                                                    f_listview.FullRowSelect = false;
                                                break;
                                            case "gridlines":
                                                if (pch.GetAttribute("gridlines") == "true")
                                                    f_listview.GridLines = true;
                                                else if (pch.GetAttribute("gridlines") == "false")
                                                    f_listview.GridLines = false;
                                                break;
                                            case "view":
                                                if (pch.GetAttribute("view") == "details")
                                                    f_listview.View = View.Details;
                                                else if (pch.GetAttribute("view") == "largeicon")
                                                    f_listview.View = View.LargeIcon;
                                                else if (pch.GetAttribute("view") == "list")
                                                    f_listview.View = View.List;
                                                else if (pch.GetAttribute("view") == "smallicon")
                                                    f_listview.View = View.SmallIcon;
                                                else if (pch.GetAttribute("view") == "tile")
                                                    f_listview.View = View.Tile;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_listview);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    //PROCESAR COLUMNAS
                                    string pxml = "<cod>" + pch.InnerXml + "</cod>";
                                    xdoc2.LoadXml(pxml);
                                    XmlNodeList xmlnode = xdoc2.GetElementsByTagName("cod");
                                    foreach (XmlElement a3 in xmlnode)
                                    {
                                        foreach (XmlElement a6 in a3.ChildNodes)
                                        {
                                            if (a6.Name == "column")
                                            {
                                                string col_name = "";
                                                string col_width = "";
                                                string col_texto = "";
                                                foreach (XmlAttribute a4 in a6.Attributes)
                                                {

                                                    if (a4.Name == "name")
                                                        col_name = a4.Value;
                                                    else if (a4.Name == "width")
                                                        col_width = a4.Value;
                                                    else if (a4.Name == "text")
                                                        col_texto = a4.Value;
                                                }
                                                f_columnheader = new ColumnHeader();
                                                f_columnheader.Name = col_name;
                                                f_columnheader.Width = Convert.ToInt32(col_width);
                                                f_columnheader.Text = col_texto;
                                                f_listview.Columns.Add(f_columnheader);
                                            }
                                        }
                                    }
                                    //====================
                                    if (!add_aotro)
                                        fo.Controls.Add(f_listview);
                                    break;
                                case "progressbar":
                                    f_progressbar = new ProgressBar();
                                    f_progressbar.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "progressbar":
                                                f_progressbar.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_progressbar.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_progressbar.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_progressbar.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_progressbar.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_progressbar.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_progressbar.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_progressbar.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_progressbar.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_progressbar.Enabled = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_progressbar);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_progressbar);
                                    break;
                                case "numericupdown":
                                    f_numericupdown = new NumericUpDown();
                                    f_numericupdown.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_numericupdown.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_numericupdown.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_numericupdown.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_numericupdown.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_numericupdown.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_numericupdown.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_numericupdown.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_numericupdown.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_numericupdown.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_numericupdown.Enabled = false;
                                                break;
                                            case "min":
                                                f_numericupdown.Minimum = Convert.ToDecimal(pch.GetAttribute("min"));
                                                break;
                                            case "max":
                                                f_numericupdown.Maximum = Convert.ToDecimal(pch.GetAttribute("max"));
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_numericupdown);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_numericupdown);
                                    break;
                                case "groupbox":
                                    f_groupbox = new GroupBox();
                                    f_groupbox.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_groupbox.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_groupbox.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_groupbox.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_groupbox.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_groupbox.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_groupbox.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_groupbox.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_groupbox.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_groupbox.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_groupbox.Enabled = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_groupbox);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_groupbox);
                                    break;
                                case "panel":
                                    f_panel = new Panel();
                                    f_panel.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_panel.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_panel.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_panel.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_panel.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_panel.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_panel.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_panel.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_panel.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_panel.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_panel.Enabled = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_panel);
                                                        }
                                                    }
                                                }
                                                break;

                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_panel);
                                    break;
                                case "tabcontrol":
                                    f_tabcontrol = new TabControl();
                                    f_tabcontrol.Text = pch.InnerText;
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        switch (pch2.Name)
                                        {
                                            case "name":
                                                f_tabcontrol.Name = pch.GetAttribute("name");
                                                break;
                                            case "backcolor":
                                                string[] rgb1 = pch.GetAttribute("backcolor").Split(new char[] { ',' });
                                                if (rgb1.Length == 3)
                                                {
                                                    f_tabcontrol.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb1[0]), Convert.ToInt32(rgb1[1]), Convert.ToInt32(rgb1[2]));
                                                }
                                                break;
                                            case "forecolor":
                                                string[] rgb2 = pch.GetAttribute("forecolor").Split(new char[] { ',' });
                                                if (rgb2.Length == 3)
                                                {
                                                    f_tabcontrol.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(rgb2[0]), Convert.ToInt32(rgb2[1]), Convert.ToInt32(rgb2[2]));
                                                }
                                                break;
                                            case "font":
                                                string[] p = pch.GetAttribute("font").Split(new char[] { ';' });
                                                f_tabcontrol.Font = new System.Drawing.Font(p[0], (float)Convert.ToInt16(p[1]));
                                                break;
                                            case "size":
                                                string[] p1 = pch.GetAttribute("size").Split(new char[] { ',' });
                                                f_tabcontrol.Size = new System.Drawing.Size(Convert.ToInt32(p1[0]), Convert.ToInt32(p1[1]));
                                                break;
                                            case "position":
                                                string[] p2 = pch.GetAttribute("position").Split(new char[] { ',' });
                                                f_tabcontrol.Location = new System.Drawing.Point(Convert.ToInt32(p2[0]), Convert.ToInt32(p2[1]));
                                                break;
                                            case "enabled":
                                                if (pch.GetAttribute("enabled") == "true")
                                                    f_tabcontrol.Enabled = true;
                                                else if (pch.GetAttribute("enabled") == "false")
                                                    f_tabcontrol.Enabled = false;
                                                break;
                                            case "visible":
                                                if (pch.GetAttribute("visible") == "true")
                                                    f_tabcontrol.Enabled = true;
                                                else if (pch.GetAttribute("visible") == "false")
                                                    f_tabcontrol.Enabled = false;
                                                break;
                                            case "groupbox":
                                                add_aotro = true;
                                                foreach (object a37 in fo.Controls)
                                                {
                                                    if (a37.GetType().ToString().Contains(".GroupBox"))
                                                    {
                                                        if (((GroupBox)a37).Name == pch.GetAttribute("groupbox"))
                                                        {
                                                            ((GroupBox)a37).Controls.Add(f_tabcontrol);
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                        //MessageBox.Show(pch2.Name + "=" + pch2.Value);
                                    }
                                    if (!add_aotro)
                                        fo.Controls.Add(f_tabcontrol);
                                    break;
                                //EVENTOS ======================================================================================
                                //============================================================0
                                //============================================================0
                                //============================================================0
                                case "event":
                                    string nombreobj = "";
                                    string nombreev = "";
                                    string nombreaccion = "";
                                    foreach (XmlAttribute pch2 in pch.Attributes)
                                    {
                                        if (pch2.Name == "object")
                                        {
                                            nombreobj = pch.GetAttribute("object");
                                        }
                                        else if (pch2.Name == "name")
                                            nombreaccion = pch.GetAttribute("name");
                                        else if (pch2.Value == "click")
                                        {
                                            if (nombreobj.Length > 0)
                                                nombreev = "click";
                                        }
                                        else if (pch2.Value == "enterkey")
                                        {
                                            if (nombreobj.Length > 0)
                                                nombreev = "enterkey";
                                        }
                                        else if (pch2.Value == "check")
                                        {
                                            if (nombreobj.Length > 0)
                                                nombreev = "check";
                                        }
                                        else if (pch2.Value == "selectindex")
                                        {
                                            if (nombreobj.Length > 0)
                                                nombreev = "selectindex";
                                        }
                                        else if (pch2.Value == "changevalue")
                                        {
                                            if (nombreobj.Length > 0)
                                                nombreev = "changevalue";
                                        }
                                        else if (pch2.Value == "doubleclick")
                                        {
                                            if (nombreobj.Length > 0)
                                                nombreev = "doubleclick";
                                        }
                                    }
                                    //ver si es boton u otro===========================================================
                                    foreach (object a3 in fo.Controls)
                                    {
                                        accion_evento_decontroles(a3, nombreobj, nombreev, nombreaccion);
                                        if (a3.GetType().ToString().Contains(".GroupBox"))
                                        {
                                            foreach (object a4 in ((GroupBox)a3).Controls)
                                            {
                                                accion_evento_decontroles(a4, nombreobj, nombreev, nombreaccion);
                                            }
                                        }
                                    }
                                    break;
                            }
                        }
                    }
                        #endregion
                }
                #region Procesar acciones
                XmlNodeList lista_a = ((XmlElement)lista[0]).GetElementsByTagName("action");
                str_acciones obj_ac;
                string atri;
                foreach (XmlElement b in lista_a)
                {
                    atri = b.GetAttribute("name");
                    obj_ac = new str_acciones();
                    obj_ac.nombre = atri;
                    obj_ac.codigoxml = b.InnerXml;
                    lista_acc.Add(obj_ac);
                }
                #endregion
                fo.Show();
            }
            catch (XmlException error32)
            {
                errorwin = new msg_error("An error occurred while trying to read XML data\r\nThe Error is: \"" + error32.Message + "\"\r\n\r\nThe XML data contains:\r\n" + original_code + "");
                errorwin.ShowDialog();
            }
        }
        #region Aqui se procesa todos los eventos
        public void evento_doubleclick_lwitem(object obj, EventArgs handler)
        {
            if (obj.GetType().ToString().Contains(".ListView"))
            {
                ListView tempbu = (ListView)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                if (tempbu.SelectedItems.Count == 1)
                                    procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
        }
        public void evento_doubleclick_arbol(object obj, EventArgs handler)
        {
            if (obj.GetType().ToString().Contains(".TreeView"))
            {
                TreeView tempbu = (TreeView)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                if (tempbu.SelectedNode.IsSelected)
                                    procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
        }
        public void evento_checked(object obj, EventArgs handler)
        {
            if (obj.GetType().ToString().Contains(".RadioButton"))
            {
                RadioButton tempbu = (RadioButton)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
            else if (obj.GetType().ToString().Contains(".CheckBox"))
            {
                CheckBox tempbu = (CheckBox)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
        }
        public void evento_click(object obj, EventArgs handler)
        {
            if (obj.GetType().ToString().Contains(".Button"))
            {
                Button tempbu = (Button)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
            else if (obj.GetType().ToString().Contains(".Label"))
            {
                Label tempbu = (Label)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
        }
        public void evento_enter(object obj, KeyEventArgs e)
        {
            if (obj.GetType().ToString().Contains(".TextBox"))
            {
                TextBox tempbu = (TextBox)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                if(e.KeyCode == Keys.Enter)
                                    procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
        }
        public void evento_doubleclick(object obj, EventArgs e)
        {
            if (obj.GetType().ToString().Contains(".ListBox"))
            {
                ListBox lbox = (ListBox)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == lbox.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                if (lbox.SelectedIndex > -1)
                                {
                                    procesar_xml_ev(a.codigoxml);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void evento_selectindex(object obj, EventArgs e)
        {
            if (obj.GetType().ToString().Contains(".ComboBox"))
            {
                ComboBox tempbu = (ComboBox)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
            else if (obj.GetType().ToString().Contains(".ListBox"))
            {
                ListBox tempbu = (ListBox)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
        }
        public void evento_changevalue(object obj, EventArgs e)
        {
            if (obj.GetType().ToString().Contains(".DateTimePicker"))
            {
                DateTimePicker tempbu = (DateTimePicker)obj;
                foreach (str_enlace_eventos a1 in lista_obj_ev)
                {
                    if (a1.objeto == tempbu.Name)
                    {
                        foreach (str_acciones a in lista_acc)
                        {
                            if (a.nombre == a1.accion)
                            {
                                procesar_xml_ev(a.codigoxml);
                            }
                        }
                    }
                }
            }
        }
        #endregion
        //proceso dentro de eventos
        #region function_eventos
        private void accion_evento_decontroles(object a3,string nombreobj,string nombreev,string nombreaccion)
        {
            if (a3.GetType().ToString().Contains(".Button"))
            {
                Button a4 = (Button)a3;
                if (a4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "click")
                    {
                        a4.Click += new EventHandler(evento_click);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
            if (a3.GetType().ToString().Contains(".RadioButton"))
            {
                RadioButton a4 = (RadioButton)a3;
                if (a4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "click")
                    {
                        a4.CheckedChanged += new EventHandler(evento_checked);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
            else if (a3.GetType().ToString().Contains(".Label"))
            {
                Label l4 = (Label)a3;
                if (l4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "click")
                    {
                        l4.Click += new EventHandler(evento_click);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
            else if (a3.GetType().ToString().Contains(".TextBox"))
            {
                TextBox t4 = (TextBox)a3;
                if (t4.Name == nombreobj)
                {
                    if (nombreev == "enterkey")
                    {
                        t4.KeyDown += new KeyEventHandler(evento_enter);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
            else if (a3.GetType().ToString().Contains(".CheckBox"))
            {
                CheckBox l4 = (CheckBox)a3;
                if (l4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "check")
                    {
                        l4.CheckedChanged += new EventHandler(evento_checked);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
            if (a3.GetType().ToString().Contains(".ComboBox"))
            {
                ComboBox a4 = (ComboBox)a3;
                if (a4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "selectindex")
                    {
                        a4.SelectedIndexChanged += new EventHandler(evento_selectindex);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }

                }
            }
            if (a3.GetType().ToString().Contains(".ListBox"))
            {
                ListBox a4 = (ListBox)a3;
                if (a4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "selectindex")
                    {
                        a4.SelectedIndexChanged += new EventHandler(evento_selectindex);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                    else if (nombreev == "doubleclick")
                    {
                        a4.MouseDoubleClick += new MouseEventHandler(evento_doubleclick);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
            if (a3.GetType().ToString().Contains(".DateTimePicker"))
            {
                DateTimePicker a4 = (DateTimePicker)a3;
                if (a4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "changevalue")
                    {
                        a4.ValueChanged += new EventHandler(evento_changevalue);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
            if (a3.GetType().ToString().Contains(".ListView"))
            {
                ListView a4 = (ListView)a3;
                if (a4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "selectindex")
                    {
                        a4.SelectedIndexChanged += new EventHandler(evento_changevalue);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                    else if (nombreev == "doubleclick")
                    {
                        a4.DoubleClick += new EventHandler(evento_doubleclick_lwitem);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
            if (a3.GetType().ToString().Contains(".TreeView"))
            {
                TreeView a4 = (TreeView)a3;
                if (a4.Name == nombreobj)
                {
                    //ver si es el click
                    if (nombreev == "doubleclick")
                    {
                        a4.DoubleClick += new EventHandler(evento_doubleclick_arbol);
                        str_enlace_eventos p5 = new str_enlace_eventos();
                        p5.objeto = nombreobj;
                        p5.accion = nombreaccion;
                        lista_obj_ev.Add(p5);
                    }
                }
            }
        }
        #endregion
        #region procesar las acciones
        public void procesar_xml_ev(string xml)
        {
            //COMPROBAR SI ES UN XML VALIDO
            ListViewItem r_listviewitem;
            bool itemcreado=false;
            bool itemtieneget=false;
            xdoc.LoadXml("<mdf>" + xml + "</mdf>");
            XmlNodeList lista = xdoc.GetElementsByTagName("mdf");
            bool existeobj = false;
            object objeto_control = new object();
            //foreach (XmlElement a in lista) <---------- INVALID CAST OPERATION, la lista cambia
            try
            {
                for (int i11 = 0; i11 <= lista.Count; i11++)
                {
                    XmlElement a = (XmlElement)lista[i11];
                    if (a != null)
                    {
                        foreach (XmlElement aa in a.ChildNodes)
                        {
                            if (aa.Name == "update")
                            {
                                string nombre_obj = "";
                                string tipo_obj = "";
                                foreach (XmlAttribute b in aa.Attributes)
                                {
                                    if (b.Name == "object")
                                        nombre_obj = b.Value;
                                }
                                for (int i1 = 0; i1 < fo.Controls.Count; i1++)
                                {
                                    if (fo.Controls[i1].Name == nombre_obj)
                                    {
                                        existeobj = true;
                                        tipo_obj = fo.Controls[i1].GetType().ToString();
                                        objeto_control = fo.Controls[i1];
                                    }
                                }
                                if (existeobj)
                                {
                                    foreach (XmlAttribute b in aa.Attributes)
                                    {
                                        if (!(b.Name == "object"))
                                        {
                                            if (tipo_obj.Contains(".TextBox"))
                                            {
                                                if (b.Name == "text")
                                                {
                                                    objeto_texto((TextBox)objeto_control, b.Value);
                                                }
                                            }
                                            else if (tipo_obj.Contains(".Label"))
                                            {
                                                if (b.Name == "text")
                                                {
                                                    objeto_texto((Label)objeto_control, b.Value);
                                                }
                                            }
                                            else if (tipo_obj.Contains(".Button"))
                                            {
                                                if (b.Name == "text")
                                                {
                                                    objeto_texto((Button)objeto_control, b.Value);
                                                }
                                            }
                                            else if (tipo_obj.Contains(".CheckBox"))
                                            {
                                                if (b.Name == "checked")
                                                {
                                                    bool p = false;
                                                    if (b.Value == "true")
                                                        p = true;
                                                    else if (b.Value == "false")
                                                        p = false;
                                                    else
                                                        MessageBox.Show("Boolean data not valid, set to False", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                    objeto_checked((CheckBox)objeto_control, p);
                                                }
                                            }
                                            else if (tipo_obj.Contains(".RadioButton"))
                                            {
                                                if (b.Name == "checked")
                                                {
                                                    bool p = false;
                                                    if (b.Value == "true")
                                                        p = true;
                                                    else if (b.Value == "false")
                                                        p = false;
                                                    else
                                                        MessageBox.Show("Boolean data not valid, set to False", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                    objeto_checked((RadioButton)objeto_control, p);
                                                }
                                            }
                                            else if (tipo_obj.Contains(".DateTimePicked"))
                                            {
                                                if (b.Name == "text")
                                                {
                                                    objeto_texto((DateTimePicker)objeto_control, b.Value);
                                                }
                                            }
                                            else if (tipo_obj.Contains(".ListBox"))
                                            {
                                                if (b.Name == "set")
                                                {
                                                    if (b.Value == "additem")
                                                    {
                                                        XmlNodeList lista_item = a.GetElementsByTagName("update");
                                                        foreach (XmlElement a2 in lista_item)
                                                        {
                                                            foreach (XmlElement a3 in a2.GetElementsByTagName("item"))
                                                            {
                                                                itemtieneget = false;
                                                                foreach (XmlElement a88 in a3.GetElementsByTagName("get"))
                                                                {
                                                                    if (a88.Name == "get")
                                                                    {
                                                                        itemtieneget = true;
                                                                        objeto_additem((ListBox)objeto_control, a3.GetAttribute("key"), obtener_valor_get(a3.FirstChild.Value));
                                                                    }
                                                                }
                                                                if (!itemtieneget)
                                                                    objeto_additem((ListBox)objeto_control, a3.GetAttribute("key"), a3.FirstChild.Value);
                                                            }
                                                        }
                                                    }
                                                    if (b.Value == "delitem")
                                                    {
                                                        XmlNodeList lista_item = a.GetElementsByTagName("update");
                                                        foreach (XmlElement a2 in lista_item)
                                                        {
                                                            foreach (XmlElement a3 in a2.GetElementsByTagName("item"))
                                                            {
                                                                //objeto_delteim((ListBox)objeto_control, a3.GetAttribute("key"), a3.FirstChild.Value);
                                                                objeto_delteim((ListBox)objeto_control, a3.GetAttribute("key"));
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else if (tipo_obj.Contains(".ComboBox"))
                                            {
                                                if (b.Name == "set")
                                                {
                                                    if (b.Value == "additem")
                                                    {
                                                        XmlNodeList lista_item = a.GetElementsByTagName("update");
                                                        foreach (XmlElement a2 in lista_item)
                                                        {
                                                            foreach (XmlElement a3 in a2.GetElementsByTagName("item"))
                                                            {
                                                                itemtieneget = false;
                                                                foreach (XmlElement a88 in a3.GetElementsByTagName("get"))
                                                                {
                                                                    if (a88.Name == "get")
                                                                    {
                                                                        itemtieneget = true;
                                                                        objeto_additem((ComboBox)objeto_control, a3.GetAttribute("key"), obtener_valor_get(a3.FirstChild.Value));
                                                                    }
                                                                }
                                                                if (!itemtieneget)
                                                                    objeto_additem((ComboBox)objeto_control, a3.GetAttribute("key"), a3.FirstChild.Value);
                                                            }
                                                        }
                                                    }
                                                    if (b.Value == "delitem")
                                                    {
                                                        XmlNodeList lista_item = a.GetElementsByTagName("update");
                                                        foreach (XmlElement a2 in lista_item)
                                                        {
                                                            foreach (XmlElement a3 in a2.GetElementsByTagName("item"))
                                                            {
                                                                //objeto_delteim((ListBox)objeto_control, a3.GetAttribute("key"), a3.FirstChild.Value);
                                                                objeto_delteim((ComboBox)objeto_control, a3.GetAttribute("key"));
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else if (tipo_obj.Contains(".ListView"))
                                            {
                                                if (b.Name == "set")
                                                {
                                                    if (b.Value == "additem")
                                                    {
                                                        r_listviewitem = new ListViewItem();
                                                        itemcreado = false;
                                                        itemtieneget = false; // <----- ANALIZAR; quizas no se use
                                                        XmlNodeList lista_item = aa.GetElementsByTagName("item");
                                                        foreach (XmlElement a3 in lista_item)
                                                        {
                                                            itemtieneget = false;
                                                            //ver si tiene un <get></get>
                                                            foreach (XmlElement a88 in a3.GetElementsByTagName("get"))
                                                            {
                                                                if (a88.Name == "get")
                                                                {
                                                                    itemtieneget = true;
                                                                    if (!itemcreado)
                                                                    {
                                                                        itemcreado = true;
                                                                        r_listviewitem.Tag = "";
                                                                        r_listviewitem.Text = obtener_valor_get(a88.GetAttribute("object"));
                                                                    }
                                                                    else
                                                                        r_listviewitem.SubItems.Add(obtener_valor_get(a88.GetAttribute("object")));
                                                                }
                                                            }
                                                            if (!itemtieneget)
                                                            {
                                                                if (!itemcreado)
                                                                {
                                                                    //MessageBox.Show(a3.Name);
                                                                    r_listviewitem.Tag = a3.GetAttribute("key");
                                                                    r_listviewitem.Text = a3.FirstChild.Value;
                                                                    itemcreado = true;
                                                                }
                                                                else
                                                                {
                                                                    r_listviewitem.SubItems.Add(a3.FirstChild.Value).Tag = a3.GetAttribute("key");
                                                                }
                                                            }
                                                        }
                                                        objeto_createitem_listview((ListView)objeto_control, r_listviewitem);
                                                        /*
                                                        XmlNodeList lista_item = aa.GetElementsByTagName("update");
                                                        foreach (XmlElement a2 in lista_item)
                                                        {
                                                            r_listviewitem = new ListViewItem();
                                                            itemcreado = false;
                                                            foreach (XmlElement a3 in a2.GetElementsByTagName("item"))
                                                            {
                                                                if (!itemcreado)
                                                                {
                                                                    r_listviewitem.Tag = a3.GetAttribute("key");
                                                                    r_listviewitem.Text = a3.FirstChild.Value;
                                                                    itemcreado = true;
                                                                }
                                                                else
                                                                {
                                                                    r_listviewitem.SubItems.Add(a3.FirstChild.Value).Tag = a3.GetAttribute("key");
                                                                }
                                                                //objecto_createitem_listview((ListBox)objeto_control, a3.GetAttribute("key"), a3.FirstChild.Value);
                                                            }
                                                            objeto_createitem_listview((ListView)objeto_control, r_listviewitem);
                                                        }
                                                        */

                                                    }
                                                    else if (b.Value == "delitem")
                                                    {
                                                        XmlNodeList lista_item = aa.GetElementsByTagName("item");
                                                        foreach (XmlElement a3 in lista_item)
                                                        {

                                                            objeto_delitem_listview((ListView)objeto_control, a3.GetAttribute("key"));
                                                        }
                                                        /*XmlNodeList lista_item = a.GetElementsByTagName("update");
                                                        foreach (XmlElement a2 in lista_item)
                                                        {
                                                            foreach (XmlElement a3 in a2.GetElementsByTagName("item"))
                                                            {
                                                                //objeto_delteim((ListBox)objeto_control, a3.GetAttribute("key"), a3.FirstChild.Value);
                                                                objeto_delitem_listview((ListView)objeto_control, a3.GetAttribute("key"));
                                                            }
                                                        }*/
                                                    }
                                                }
                                            }
                                            else if (tipo_obj.Contains(".ProgressBar"))
                                            {
                                                if (b.Name == "set")
                                                {
                                                    objeto_progressbar((ProgressBar)objeto_control, b.Value);
                                                }
                                            }
                                            else if (tipo_obj.Contains(".TreeView"))
                                            {
                                                string tr_valor = "";
                                                string tr_key = "";
                                                string tr_subkey = "";
                                                bool essubitem = false;
                                                bool existeget = false;
                                                if (b.Name == "set")
                                                {
                                                    if (b.Value == "additem")
                                                    {
                                                        XmlNodeList lista_item = a.GetElementsByTagName("update");
                                                        foreach (XmlElement a2 in lista_item)
                                                        {
                                                            foreach (XmlElement a3 in a2.GetElementsByTagName("item"))
                                                            {
                                                                existeget = false;
                                                                foreach (XmlElement a88 in a3.GetElementsByTagName("get"))
                                                                {
                                                                    existeget = true;
                                                                    if (a3.GetAttribute("subitem").Length == 0)
                                                                    {
                                                                        //objeto_additem_tree((TreeView)objeto_control,a3.GetAttribute("key"),a3.FirstChild.Value);
                                                                        tr_key = a3.GetAttribute("key");
                                                                        tr_valor = obtener_valor_get(a88.GetAttribute("object"));
                                                                        essubitem = false;
                                                                    }
                                                                    else
                                                                    {
                                                                        tr_key = a3.GetAttribute("key");
                                                                        tr_valor = obtener_valor_get(a88.GetAttribute("object"));
                                                                        tr_subkey = a3.GetAttribute("subitem");
                                                                        essubitem = true;
                                                                    }
                                                                }
                                                                if (!existeget)
                                                                {
                                                                    if (a3.GetAttribute("subitem").Length == 0)
                                                                    {
                                                                        //objeto_additem_tree((TreeView)objeto_control,a3.GetAttribute("key"),a3.FirstChild.Value);
                                                                        tr_key = a3.GetAttribute("key");
                                                                        tr_valor = a3.FirstChild.Value;
                                                                        essubitem = false;
                                                                    }
                                                                    else
                                                                    {
                                                                        tr_key = a3.GetAttribute("key");
                                                                        tr_valor = a3.FirstChild.Value;
                                                                        tr_subkey = a3.GetAttribute("subitem");
                                                                        essubitem = true;
                                                                    }
                                                                }
                                                                if (essubitem)
                                                                    objeto_additem_tree((TreeView)objeto_control, tr_subkey, tr_key, tr_valor);
                                                                else
                                                                    objeto_additem_tree((TreeView)objeto_control, tr_key, tr_valor);
                                                            }
                                                        }
                                                        //objeto_additem_tree((TreeView)objeto_control,
                                                    }
                                                    else if (b.Value == "delitem")
                                                    {

                                                    }
                                                }
                                            }
                                            else if (tipo_obj.Contains(".TabControl"))
                                            {
                                                //
                                            }
                                        }
                                    }
                                }
                                else
                                    MessageBox.Show("El objeto al que haces referencia no existe: " + nombre_obj, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                            }
                            else if (aa.Name == "send")
                            {
                                string obtpag = aa.GetAttribute("run");
                                string pmeto = aa.GetAttribute("method");
                                string paramets = "";

                                string tem_nombrep = "";
                                string tem_nombrev = "";
                                XmlNodeList lista_parametrs = aa.GetElementsByTagName("param");
                                foreach (XmlElement a7 in lista_parametrs)
                                {
                                    tem_nombrep = "";
                                    tem_nombrev = "";
                                    if (a7.GetAttribute("name") != null)
                                    {
                                        tem_nombrep = a7.GetAttribute("name");
                                    }
                                    if (a7.ChildNodes[0].Name == "get")
                                    {
                                        foreach (object lob in fo.Controls)
                                        {
                                            if (lob.GetType().ToString().Contains(".TextBox"))
                                            {
                                                if (((TextBox)lob).Name == a7.ChildNodes[0].Attributes["object"].Value)
                                                {
                                                    tem_nombrev = ((TextBox)lob).Text;
                                                }
                                            }
                                        }
                                    }
                                    else if (a7.ChildNodes[0].Name == "#text")
                                    {
                                        tem_nombrev = a7.ChildNodes[0].Value;
                                    }
                                    if (tem_nombrep.Length > 0)
                                    {
                                        if (paramets.Length == 0)
                                            paramets = tem_nombrep + "=" + tem_nombrev;
                                        else
                                            paramets += "&" + tem_nombrep + "=" + tem_nombrev;
                                    }
                                    //XmlNodeList lista_objs = a7.GetElementsByTagName("get");

                                }
                                get_web.asyn_cargarpagina(obtpag, paramets, "POST", false, false);
                                consola.escribir("SEND data to " + obtpag + " with parameters " + paramets);
                            }
                            else if (aa.Name == "show")
                            {
                                //MessageBox.Show(aa.InnerXml);
                                if (aa.GetAttribute("url") == null)
                                {
                                    //getxml pnew = new getxml();
                                    //pnew.get_xml("<mdf>" + aa.InnerXml + "</mdf>",);
                                    Application.Run(new Form1(aa.InnerXml));
                                }
                                else
                                {
                                    if (aa.GetAttribute("url").Length > 0)
                                    {
                                        string p_cat = "ver=1";
                                        string p_met = "POST";
                                        if (aa.GetAttribute("parameters").Length > 0)
                                            p_cat = aa.GetAttribute("parameters");
                                        if (aa.GetAttribute("method").Length > 0)
                                            p_met = aa.GetAttribute("method");
                                        else
                                            p_met = "POST";
                                        get_web.asyn_cargarpagina(aa.GetAttribute("url"), p_cat, p_met, false, true);
                                    }
                                    else
                                        MessageBox.Show("URL Attribute is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else if (aa.Name == "msgbox")
                            {
                                string mb_mensaj = "";
                                string titul = "";
                                MessageBoxButtons mbut = MessageBoxButtons.OK;
                                MessageBoxIcon mico = MessageBoxIcon.None;
                                if (aa.GetAttribute("text") != null)
                                    mb_mensaj = aa.GetAttribute("text");
                                if (aa.GetAttribute("title") != null)
                                    titul = aa.GetAttribute("title");
                                if (aa.GetAttribute("buttons") != null)
                                {
                                    switch (aa.GetAttribute("buttons"))
                                    {
                                        case "ok":
                                            mbut = MessageBoxButtons.OK;
                                            break;
                                        case "okcancel":
                                            mbut = MessageBoxButtons.OKCancel;
                                            break;
                                        case "yesno":
                                            mbut = MessageBoxButtons.YesNo;
                                            break;
                                        case "yesnocancel":
                                            mbut = MessageBoxButtons.YesNoCancel;
                                            break;
                                    }
                                }
                                if (aa.GetAttribute("icon") != null)
                                {
                                    switch (aa.GetAttribute("icon"))
                                    {
                                        case "asterisk":
                                            mico = MessageBoxIcon.Asterisk;
                                            break;
                                        case "error":
                                            mico = MessageBoxIcon.Error;
                                            break;
                                        case "exclamation":
                                            mico = MessageBoxIcon.Exclamation;
                                            break;
                                        case "hand":
                                            mico = MessageBoxIcon.Hand;
                                            break;
                                        case "information":
                                            mico = MessageBoxIcon.Information;
                                            break;
                                        case "question":
                                            mico = MessageBoxIcon.Question;
                                            break;
                                        case "stop":
                                            mico = MessageBoxIcon.Stop;
                                            break;
                                        case "warning":
                                            mico = MessageBoxIcon.Warning;
                                            break;
                                    }
                                }
                                MessageBox.Show(mb_mensaj, titul, mbut, mico);
                                break;
                            }
                        }
                    }
                }
            }
            catch (InvalidCastException e)
            {
                errorwin = new msg_error("There was a 'InvalidCastException' exception, the error is:\r\n" + e.Message + "\r\n\r\nThe XML Data is:\r\n" + xml);
                errorwin.ShowDialog();
            }
        }
        private void objeto_additem_tree(TreeView p, string subitem, string key, string valor)
        {
            if (p.Nodes.ContainsKey(subitem))
            {
                TreeNode a = p.Nodes[subitem];
                a.Nodes.Add(key, valor);
            }
        }
        private void objeto_additem_tree(TreeView p, string key, string valor)
        {
            TreeNode a = p.Nodes.Add(key, valor);
        }
        private void objeto_progressbar(ProgressBar p, string valor)
        {
            p.Value = Convert.ToInt32(valor);
        }
        private void objeto_delitem_listview(ListView p, string key)
        {
            ArrayList lista_bo = new ArrayList();
            foreach (ListViewItem a in p.Items)
            {
                if (p.Tag.ToString() == key)
                    lista_bo.Add(a);
            }
            foreach (ListViewItem b in lista_bo)
                p.Items.Remove(b);
        }
        private void objeto_createitem_listview(ListView p, ListViewItem a)
        {
            p.Items.Add(a);
        }

        private void objeto_delteim(ListBox p, string key)
        {
            ArrayList lista_abo = new ArrayList();
            foreach (ListBox_Item a in p.Items)
            {
                if (a.Key == key)
                    lista_abo.Add(a);
            }
            foreach (ListBox_Item a in lista_abo)
                p.Items.Remove(a);
            
        }
        private void objeto_delteim(ComboBox p, string key)
        {
            ArrayList lista_abo = new ArrayList();
            foreach (ListBox_Item a in p.Items)
            {
                if (a.Key == key)
                    lista_abo.Add(a);
            }
            foreach (ListBox_Item a in lista_abo)
                p.Items.Remove(a);

        }
        private void objeto_additem(ListBox p, string key, string value)
        {
            p.Items.Add(new ListBox_Item(value,key));
        }
        private void objeto_additem(ComboBox p, string key, string value)
        {
            p.Items.Add(new ListBox_Item(value, key));
        }
        private void objeto_checked(RadioButton p, bool value)
        {
            p.Checked = value;
        }
        private void objeto_checked(CheckBox p, bool value)
        {
            p.Checked = value;
        }
        private void objeto_texto(TextBox p, string texto)
        {
            p.Text = texto;
        }
        private void objeto_texto(Label p, string texto)
        {
            p.Text = texto;
        }
        private void objeto_texto(Button p, string texto)
        {
            p.Text = texto;
        }
        private void objeto_texto(DateTimePicker p, string texto)
        {
            p.Value = Convert.ToDateTime(texto);
        }
        private string obtener_valor_get(string nombre_obj)
        {
            string pdevo = "";
            bool yaencontrado=false;
            foreach (object lob in fo.Controls)
            {
                //textbox
                if (lob.GetType().ToString().Contains(".TextBox"))
                {
                    if (((TextBox)lob).Name == nombre_obj)
                    {
                        pdevo = ((TextBox)lob).Text;
                        yaencontrado = true;
                    }
                }
                else if (lob.GetType().ToString().Contains(".DateTimePicker"))
                {
                    if (((DateTimePicker)lob).Name == nombre_obj)
                    {
                        pdevo = ((DateTimePicker)lob).Text;
                        yaencontrado = true;
                    }
                }
                else if (lob.GetType().ToString().Contains(".ListBox"))
                {
                    if (((ListBox)lob).Name == nombre_obj)
                    {
                        pdevo = ((ListBox_Item)(((ListBox)lob).SelectedItem)).Contenido;
                        yaencontrado = true;
                    }
                }
                else if (lob.GetType().ToString().Contains(".ComboBox"))
                {
                    if (((ComboBox)lob).Name == nombre_obj)
                    {
                        pdevo = ((ComboBox)lob).Text;
                        yaencontrado = true;
                    }
                }
                else if (lob.GetType().ToString().Contains(".ListView"))
                {
                    if (((ListView)lob).Name == nombre_obj)
                    {
                        pdevo = ((ListView)lob).SelectedItems[0].Text;
                        yaencontrado = true;
                    }
                }
                else if (lob.GetType().ToString().Contains(".TreeView"))
                {
                    if (((TreeView)lob).Name == nombre_obj)
                    {
                        pdevo = ((TreeView)lob).SelectedNode.Text;
                        yaencontrado = true;
                    }
                }
            }
            if (!yaencontrado)
            {
                foreach (object lob2 in fo.Controls)
                {
                    if (lob2.GetType().ToString().Contains(".GroupBox"))
                    {
                        foreach (object lob3 in ((GroupBox)lob2).Controls)
                        {
                            if (lob3.GetType().ToString().Contains(".TextBox"))
                            {
                                if (((TextBox)lob3).Name == nombre_obj)
                                {
                                    pdevo = ((TextBox)lob3).Text;
                                    yaencontrado = true;
                                }
                            }
                            else if (lob3.GetType().ToString().Contains(".DateTimePicker"))
                            {
                                if (((DateTimePicker)lob3).Name == nombre_obj)
                                {
                                    pdevo = ((DateTimePicker)lob3).Text;
                                    yaencontrado = true;
                                }
                            }
                            else if (lob3.GetType().ToString().Contains(".ListBox"))
                            {
                                if (((ListBox)lob3).Name == nombre_obj)
                                {
                                    pdevo = ((ListBox_Item)(((ListBox)lob3).SelectedItem)).Contenido;
                                }
                            }
                            else if (lob3.GetType().ToString().Contains(".ComboBox"))
                            {
                                if (((ComboBox)lob3).Name == nombre_obj)
                                {
                                    pdevo = ((ComboBox)lob3).Text;
                                    yaencontrado = true;
                                }
                            }
                        }
                    }
                }
            }
            return pdevo;
        }
        #endregion

    }
}
